home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1910 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  55 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with simple code
  5. Date: 17 Jan 1996 19:27:46 GMT
  6. Organization: OpenVision
  7. Message-ID: <4djiji$70n@spanky.pls.ov.com>
  8. References: <4dbak5$oij@ionews.io.org>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article oij@ionews.io.org, jgordon@io.org (John Gordon MacPherson) writes:
  13. >Can anyone tell me what's wrong with this piece of code? I lifted it
  14. >straight from a textbook.
  15. >
  16. >Here's the code:
  17. >
  18. >/* Calculating compound interest */
  19. >#include <stdio.h>
  20. >#include <math.h>
  21. >
  22. >main()
  23. >{
  24. >    int year;
  25. >    double amount, principal = 1000, rate = 0.5;
  26. >
  27. >    printf("%4s%21s\n", "Year", "Amount on deposit");
  28. >
  29. >    for (year = 1; year <= 10; year++) {
  30. >        amount = principal * pow(1.0 + rate, year);
  31. >        printf("%4d%21.2f\n", year, amount);
  32. >    }
  33. >
  34. >    return 0;
  35. >}
  36. >______________________________________________________________
  37. >
  38. >and here's the error:
  39. >
  40. >In function `main':
  41. >undefined reference to `pow'
  42. >
  43. >I don't understand. `pow' is a function, not a variable?
  44. >Can anyone tell me what's wrong?
  45. >
  46. >
  47.  
  48.  
  49. You need to add "-lm" to the end of your compile line.  This command will
  50. include the math library that defines the pow() function.
  51.  
  52.             Fletcher.Glenn@ov.com
  53.  
  54.  
  55.